<!DOCTYPE html>
<html>


<!-- Mirrored from www.zi-han.net/theme/hplus/table_jqgrid.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:20:02 GMT -->
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>资源编辑</title>
    <meta name="keywords" content="资源添加">
    <meta name="description" content="资源添加">

    <link rel="shortcut icon" href="favicon.ico">

    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/bootstrap/css/bootstrap.min.css'"
          href="../asset/js/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/fonts/iconfont.css'"
          href="../asset/css/fonts/iconfont.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/jqgrid/ui.jqgridffe4.css'"
          href="../asset/js/plugins/jqgrid/ui.jqgridffe4.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/animate.min.css'" href="../asset/css/animate.min.css"
          rel="stylesheet">

    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/font-awesome.min.css'" rel="stylesheet"
          href="../asset/css/font-awesome.min.css"
    />
    <link rel="stylesheet" th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/ztree/css/zTreeStyle/zTreeStyle.css'"
          href="../asset/js/ztree/css/zTreeStyle/zTreeStyle.css"/>
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/style.min862f.css'"
          href="../asset/css/style.min862f.css" rel="stylesheet">


</head>

<body class="gray-bg">


<div class="wrapper wrapper-content  animated fadeInRight">


    <div class="ibox float-e-margins">
        <div class="ibox-title">
            资源信息
        </div>
        <div class="row ibox-content">
            <form class="form-horizontal m-t" id="formSubmit">
                <div class="col-sm-3">

                    <div class="ibox" style="overflow-y: auto;overflow-x: auto;height: 300px;">
                        <div class="ibox-title">
                            父资源
                        </div>
                        <div class="ibox-content">
                            <ul id="tree" class="ztree"></ul>
                        </div>
                    </div>

                </div>
                <div class="col-sm-9">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">资源类别：</label>
                        <div class="col-sm-4">
                            <input type="hidden" name="id" id="id"/>
                            <input type="hidden" name="parentId" id="parentId"/>
                            <input type="hidden" name="parentIds" id="parentIds"/>
                            <select class="form-control m-b" id="type" name="type">
                                <option value="" selected="selected">请选择</option>
                            </select>
                        </div>
                        <label class="col-sm-2 control-label">名称：</label>
                        <div class="col-sm-4">
                            <input id="name" name="name" class="form-control" type="text">
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">权限值：</label>
                        <div class="col-sm-4">
                            <input id="permission" name="permission" class="form-control" type="text">
                        </div>
                        <label class="col-sm-2 control-label">是否显示：</label>
                        <div class="col-sm-4">
                            <select class="form-control m-b" id="isShow" name="isShow">
                                <option value="1" selected="selected">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">图标：</label>
                        <div class="col-sm-4">
                            <input id="icon" name="icon" class="form-control" type="text">
                        </div>
                        <label class="col-sm-2 control-label">排序：</label>
                        <div class="col-sm-4">
                            <input id="sort" name="sort" class="form-control" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">路径：</label>
                        <div class="col-sm-10">
                            <input id="href" name="href" class="form-control" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">备注：</label>
                        <div class="col-sm-10">
                            <textarea id="remarks" name="remarks" class="form-control"></textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-8 col-sm-offset-3">
                            <button class="btn btn-primary" id="btnSubmit" type="submit">提交</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

</div>

<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/jquery/jQuery-2.2.0.min.js'"
        src="../asset/js/jquery/jQuery-2.2.0.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/bootstrap/js/bootstrap.min.js'"
        src="../asset/js/bootstrap/js/bootstrap.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/content.min.js'"
        src="../asset/js/content.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/validate/jquery.validate.min.js'"
        src="../asset/js/plugins/validate/jquery.validate.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/layer/layer.js'"
        src="../asset/js/plugins/layer/layer.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/validate/messages_zh.min.js'"
        src="../asset/js/plugins/validate/messages_zh.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/ztree/js/jquery.ztree.core.min.js'"
        src="../asset/js/ztree/js/jquery.ztree.core.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/ztree/js/jquery.ztree.excheck.min.js'"
        src="../asset/js/ztree/js/jquery.ztree.excheck.min.js"></script>

<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/comm.js'" src="../asset/js/comm.js"></script>
<script type="text/javascript">

    var zTreeObj=undefined;
    function initView() {

        //字典初始化
        getType();

    }
    //初始化上级字典
    function getType() {
        app.post("/admin/dict/get_by_parentid", {'pValue':'menu_type'}, function (data) {
            if (data && data.length > 0) {
                var html = '';
                $.each(data, function (index, item) {
                    html += '<option value="' + item.value + '">' + item.label + '</option>';
                });
                $("#type").append(html);
            }
            getDetail();
        });
    }
    //渲染界面编辑数据
    function initFormView(data) {
        app.initFormView("#formSubmit", data);
    }

    //获取数据
    function getDetail() {
        var id = app.getRequest()["id"];
        if (id && id.length > 0) {//编辑
            app.post("/admin/menu/detail", {id: id}, function (data) {
                initFormView(data);
                initmenu(data.parentId);
            });
        }else {
            initmenu();
        }

    }
    
    //父资源id的组合
    function getMenusIdsStr(treeNode) {
        var ids="";
        var parentNode=treeNode.getParentNode();
        if(parentNode!=null){
            ids=getMenusIdsStr(parentNode)+","+parentNode.id;
        }
        return ids;
    }
    
    //初始化左侧菜单
    function initmenu(ckId) {
        //初始化树结构
        var setting = {
            async: {
                enable: true,
                url: "/admin/menu/treeAndCheck?ckId="+ckId,
                autoParam: ["id"]
            },
            check: {
                enable: true,
                chkStyle: "radio"
            },
            view: {
                selectedMulti: false,
                showLine: true
            },
            callback: {
                onCheck: function (event, treeId, treeNode) {
                    $("#parentId").val(treeNode.id);
                    var ids="0"+getMenusIdsStr(treeNode)+","+treeNode.id;
                    $("#parentIds").val(ids);
                    console.log(ids);
                }
                ,
                onAsyncSuccess: function (event, treeId, treeNode, msg) {
                    var treeObj = $.fn.zTree.getZTreeObj(treeId);
                    treeObj.expandAll(true);

                }
            }
        };
        zTreeObj = $.fn.zTree.init($("#tree"), setting);
    }

    $().ready(function () {
        //渲染界面
        initView();
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            }, success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
        })
        var e = "<i class='fa fa-times-circle'></i> ";
        var formValidate = {
            rules: {
                type: "required",
                name: "required",
                permission: "required",
                parentId: "required",
                sort: "required"
            },
            messages: {
                type: e + "请选择资源类别",
                name: e + "请输入名称",
                permission: e + "请输入权限值",
                parentId: e + "请选择父资源",
                sort: e + "请输入排序"
            },
            debug: true,
            submitHandler: function (form) {
                var parm = $("#formSubmit").serialize();
                var p=$("#parentId").val();
                if(!p||p.length<=0){
                    app.tip("请选择父资源！");
                    return;
                }
                app.post("/admin/menu/edit", parm, function (data) {
                    app.close();
                    var grid = window.parent.location.reload(); //刷新父页面
                });
            }
        };
        $("#formSubmit").validate(formValidate);
    });
</script>
</body>
</html>
